package com.lin.missyou.lib;

import com.lin.missyou.exception.http.ServerErrorException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author gcq
 * @Create 2021-11-22
 */
public class LinWxNotify {
    /**
     * 获取支付回调结果
     *
     * @param inputStream
     * @return
     */
    public static String readNotify(InputStream inputStream) {
        // 读取 inputStream
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        // 流转换车成 字符串
        StringBuilder builder = new StringBuilder();
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                builder.append(line).append("\n");
            }
        } catch (IOException e) {
            throw new ServerErrorException(9999);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return builder.toString();
    }
    /**
     * 支付失败通知
     *
     * @return
     */
    public static String fail() {
        return "false";
    }

    /**
     * 支付成功通知
     *
     * @return
     */
    public static String success() {
        return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
    }
}